﻿using FrameworkCore.Interfaces;
using Infrastructure;
using Infrastructure.Events;
using MediatR;
using Serilog.Core;
using Serilog.Events;

namespace FrameworkCore.Extensions;

public class CustomDatabaseLogSink : ILogEventSink
{
    private readonly ICurrentUserService _userService;

    private readonly IMediator _mediator;

    public CustomDatabaseLogSink(
        ICurrentUserService userService,
        IMediator mediator)
    {
        _userService = userService;
        _mediator = mediator;
    }

    public void Emit(LogEvent logEvent)
    {
        _mediator.Publish(new LoggerEvent(logEvent, _userService));
    }
}
